package com.joyxy.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.util.Map;

/**
 * 游戏配置类
 */
public class GameConfig {
    private static final Logger logger = LoggerFactory.getLogger(GameConfig.class);
    
    private String gameName;
    private String gameExecutable;
    private int windowWidth = 1920;
    private int windowHeight = 1080;
    private int automationInterval = 1000;
    private double imageMatchThreshold = 0.8;
    private Map<String, Object> gameSpecificSettings;
    
    public static GameConfig load(String configPath) throws IOException {
        File configFile = new File(configPath);
        
        if (!configFile.exists()) {
            logger.warn("配置文件不存在: {}, 使用默认配置", configPath);
            return createDefault();
        }
        
        ObjectMapper mapper = new ObjectMapper();
        GameConfig config = mapper.readValue(configFile, GameConfig.class);
        
        logger.info("加载游戏配置: {}", configPath);
        return config;
    }
    
    private static GameConfig createDefault() {
        GameConfig config = new GameConfig();
        config.setGameName("默认游戏");
        config.setGameExecutable("game.exe");
        return config;
    }
    
    // Getters and Setters
    public String getGameName() {
        return gameName;
    }
    
    public void setGameName(String gameName) {
        this.gameName = gameName;
    }
    
    public String getGameExecutable() {
        return gameExecutable;
    }
    
    public void setGameExecutable(String gameExecutable) {
        this.gameExecutable = gameExecutable;
    }
    
    public int getWindowWidth() {
        return windowWidth;
    }
    
    public void setWindowWidth(int windowWidth) {
        this.windowWidth = windowWidth;
    }
    
    public int getWindowHeight() {
        return windowHeight;
    }
    
    public void setWindowHeight(int windowHeight) {
        this.windowHeight = windowHeight;
    }
    
    public int getAutomationInterval() {
        return automationInterval;
    }
    
    public void setAutomationInterval(int automationInterval) {
        this.automationInterval = automationInterval;
    }
    
    public double getImageMatchThreshold() {
        return imageMatchThreshold;
    }
    
    public void setImageMatchThreshold(double imageMatchThreshold) {
        this.imageMatchThreshold = imageMatchThreshold;
    }
    
    public Map<String, Object> getGameSpecificSettings() {
        return gameSpecificSettings;
    }
    
    public void setGameSpecificSettings(Map<String, Object> gameSpecificSettings) {
        this.gameSpecificSettings = gameSpecificSettings;
    }
} 